import request from "@/utils/request";

const BASE_URL = "/api/v1/category";

const categoryApi = {
  getPage(params?: PageQuery) {
    return request<any, PageResult<SysMaterialCategoryVO[]>>({
      url: `${BASE_URL}/page`,
      method: "get",
      params,
    });
  },
  getById(id?: string) {
    return request<any, PageResult<SysMaterialCategoryVO[]>>({
      url: `${BASE_URL}/${id}/form`,
      method: "get",
    });
  },
  add(data: SysMaterialCategoryForm) {
    return request({
      url: `${BASE_URL}/add`,
      method: "post",
      data,
    });
  },
  delete(ids: string) {
    return request({
      url: `${BASE_URL}/${ids}`,
      method: "delete",
    });
  },
  update(data: SysMaterialCategoryForm) {
    return request({
      url: `${BASE_URL}/edit`,
      method: "put",
      data,
    });
  },
  categoryList(data: any) {
    return request({
      url: `/api/v1/requirementCategory/list`,
      method: "get",
      params: data,
    });
  },
};

export default categoryApi;

/**
 * 材料品类对象
 */
export interface SysMaterialCategoryVO {
  /** 主键 ID */
  id: number;

  /** 品类代码 */
  code: string;

  /** 品类名称 */
  name: string;

  /** 分类级别 */
  level: number;

  /** 父级行品类代码 */
  parentCode: string;

  /** 品类预算比例 */
  budgetRatio: string;
}

/**
 * 材料品类表单对象
 */
export interface SysMaterialCategoryForm {
  /** 主键 ID */
  id: number;

  /** 品类代码 */
  code: string;

  /** 品类名称 */
  name: string;

  /** 分类级别 */
  level: number;

  /** 父级行政区划代码 */
  parentCode?: string;

  /** 品类预算比例 */
  budgetRatio?: string;
}
